<template>
  <div class="input-box">
    <input type="text" placeholder="输入任务名称" v-model="inputText" />
    <span @click="add">新增</span>
  </div>
</template>

<script setup>
import { ref } from "vue";
//从对应模块的文件中导入useCounterStore方法
import { useCounterStore } from "../stores/counter";
//调用useCounterStore方法 获取store对象
var store = useCounterStore();

var inputText = ref("");
var add = () => {
  if (inputText.value) {
    store.addTask(inputText.value);
    inputText.value = "";
    console.log(store.tasklist);
  } else {
    alert("任务名称不能为空!");
  }
};

</script>

<style scoped>
.input-box {
  display: flex;
  align-items: center;
  padding: 10px;
}
.input-box input {
  height: 40px;
  flex: 1;
  border: 1px solid #ccc;
  outline: none;
  padding-left: 20px;
  border-radius: 5px;
}
.input-box span {
  width: 80px;
  display: inline-block;
  text-align: center;
  line-height: 40px;
  color: rgb(33, 146, 216);
}
</style>